<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  function isObject(obj) {
    return typeof obj === 'object' && obj !== null
  }

  function isEqual(obj1, obj2) {
    if (!isObject(obj1) || !isObject(obj2)) {
      return obj1 === obj2
    }
    if (obj1 === obj2) {
      return true
    }
    //两个都是对象或者数组，且不相等
    //1.取出obj1和obj2的keys，比较个数
    const obj1Keys = Object.keys(obj1)
    const obj2Keys = Object.keys(obj2)
    if (obj1Keys.length !== obj2Keys.length) {
      return false
    }
    //2.以obj1为基准，和obj2依次递归比较
    for (let key in obj1) {
      const res = isEqual(obj1[key], obj2[key])
      if (!res) {
        return false
      }
    }
    return true
  }



  const obj1 = {
    a: 100,
    b: {
      x: 123,
      y: 456
    }
  }
  const obj2 = {
    a: 100,
    b: {
      x: 123,
      y: 456
    }
  }

  console.log(isEqual(obj1, obj2))
</script>

</html>